﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;


public partial class Admin_Manage_WeChatConfig : AdminBase
{
    public int _Id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";


        if (!Page.IsPostBack)
        {
            Entities db = new Entities();
            var _mg = db.WeChatConfig.FirstOrDefault();
            if (_mg != null)
            {
                txtAPPID.Text = _mg.APPID;
                txtAPPSECRET.Text = _mg.APPSECRET;
                txtKEY.Text = _mg.KEY;
                txtMCHID.Text = _mg.MCHID;
                txtPayUrl.Text = _mg.PayUrl;
                txtWeChatName.Text = _mg.WeChatName;
                txtPayAPI.Text = _mg.PayAPI;
            }
        }
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities db = new Entities();
        WeChatConfig WConfig = new WeChatConfig();
        
        if (_Id != 0)
            WConfig = db.WeChatConfig.First(p => p.Id == _Id);
        WConfig.WeChatName = txtWeChatName.Text.Trim();
        WConfig.APPID = txtAPPID.Text.Trim();
        WConfig.APPSECRET = txtAPPSECRET.Text.Trim();
        WConfig.KEY = txtKEY.Text.Trim();
        WConfig.MCHID = txtMCHID.Text.Trim();
        WConfig.PayUrl = txtPayUrl.Text.Trim();
        WConfig.PayAPI = txtPayAPI.Text.Trim();

        if (_Id == 0)
        {
            db.WeChatConfig.Add(WConfig);
            db.SaveChanges();
            Response.Write("<script> var success=1;</script>");
        }
        else
        {
            db.SaveChanges();
            Response.Write("<script> var success=1;</script>");
        }

       
    }
  





}